﻿using System.Xml.Linq;

namespace SharePoint.Orm.Caml {
	///<summary>
	/// If the FieldRef is AssignedTo, and AssignedTo is set to group X, then this class will return 
	/// the CAML to determine if the current user is a member of group X.
	///</summary>
	public class CamlCurrentUserGroupMember : CamlExpr {
		private CamlFieldRef _fieldRef { get; set; }
		
		///<summary>
		/// CamlFieldRef is required.
		///</summary>
		///<param name="fieldRef">The field to check for membership.</param>
		public CamlCurrentUserGroupMember(CamlFieldRef fieldRef) {
			_fieldRef = fieldRef;
		}

		///<summary>
		/// Returns the CAML to determine if the current user is a member of the group assigned to FieldRef.
		///</summary>
		///<returns></returns>
		public override XObject ToXml() {
			return new XElement("Membership",
				new XAttribute("Type", "CurrentUserGroups"),
				_fieldRef.ToXml()
				);
		}
	}
}
